#define _init__c

#include    "includeAll.h"

void InitRegister ()
{

	TMOD = 0x11;		        //16bit timer0&timer1
	TH0 = (65536-14744)/256;	//2ms timer0 interrupt
	TL0 = (65536-14744)%256;
	//TH1 = (65536-1)/256;		//20ms timer1 interrupt
	//TL1 = (65536-1)%256;
	TH2 = (65536-450)/256;      //0.125ms==2khz timer2 interrupt
	TL2 = (65536-450)%256;
	RCP2H = TH2  ;
	RCP2L = TL2  ;
	//INTE1|=b0000_0010;
	//P1WKUP|=b0010_0000;
	IPH=0x20;
	IP=0x20;
	ET0 = 1;			//timer0 interrupt enable
	TR0 = 1;			//timer0 running
	ET1 = 1;            //timer1 interrupt enable
	//TR1 = 1;            //timer1 running
	ET2 = 1;            //timer2 interrupt enable
	TR2 = 1;            //timer2 running
	EA = 1;
}



void InitIoport ()
{

	//P0OE&=0x00;
	P1MODL &=0x00;
	P1MODH &=0x00;
	P2MOD &=0x00;
	P3MODL &=0x00;
	P3MODH &=0x00;
	//P3MODH |=b0000_0010;
	//  P3MODH |= b0010_1000;
	P1MODL|=b1010_0000;
	P1MODH|=b1000_0000;
	P3MODH|=b0010_0010;
	P2MOD|=b0000_0010;
	F_clrPowerL;
	clrBengJDQ;
//     F_clrPowerH;
	 //P1_7=1;
	P1_6=1;
}

void iap_on()
{
	EA=0;
	   SWCMD=0x65;
	INTE1|=b10100000;
}

void iap_off()
{
	SWCMD=0x00;
	INTE1&=b00011111;
	EA=1;
}

void iap_read()
{
	iap_on();
	setCurTemp=*(uint8_t xdata *)(0x1fe0);
	gear=*(uint8_t xdata *)(0x1fe1);
	
	orderClockOpenHour=*(uint8_t xdata *)(0x1fe2);
	orderClockOpenMin=*(uint8_t xdata *)(0x1fe3);
	orderClockCloseHour=*(uint8_t xdata *)(0x1fe4);
	orderClockCloseMin=*(uint8_t xdata *)(0x1fe5);
	
		// AorderClockOpenHour=*(uint8_t xdata *)(0x1fe6);
	// AorderClockOpenMin=*(uint8_t xdata *)(0x1fe7);
	// AorderClockCloseHour=*(uint8_t xdata *)(0x1fe8);
	// AorderClockCloseMin=*(uint8_t xdata *)(0x1fe9);
	
	
	// NorderClockOpenMin=*(uint8_t xdata *)(0x1fea);
// NorderClockCloseHour=*(uint8_t xdata *)(0x1feb);
	// NorderClockCloseMin=*(uint8_t xdata *)(0x1fec);
	// NorderClockOpenHour=*(uint8_t xdata *)(0x1fed);
	function=*(uint8_t xdata *)(0x1fee);
		checkNum1=*(uint8_t xdata *)(0x1fe6);
	checkNum2=*(uint8_t xdata *)(0x1fe7);
	
	
	lastCurTemp=*(uint8_t xdata *)(0x1fe8);
	lastGear=*(uint8_t xdata *)(0x1fe9);
	iap_off();
}

void iap_write()
{
	iap_on();
	*(uint8_t xdata *)(0x1fe0)=setCurTemp;
	*(uint8_t xdata *)(0x1fe1)=gear;
	
*(uint8_t xdata *)(0x1fe2)		=			orderClockOpenHour	;
*(uint8_t xdata *)(0x1fe3)	=				orderClockOpenMin  	;
*(uint8_t xdata *)(0x1fe4)		=			orderClockCloseHour		;
*(uint8_t xdata *)(0x1fe5)		=			orderClockCloseMin		;
					
// *(uint8_t xdata *)(0x1fe6)		=			AorderClockOpenHour	  ;
// *(uint8_t xdata *)(0x1fe7)		=			AorderClockOpenMin		;
// *(uint8_t xdata *)(0x1fe8)		=			AorderClockCloseHour		;
// *(uint8_t xdata *)(0x1fe9)		=			AorderClockCloseMin		;
					
					
// *(uint8_t xdata *)(0x1fea)		=			NorderClockOpenMin		;
// *(uint8_t xdata *)(0x1feb)			=		NorderClockCloseHour			;
// *(uint8_t xdata *)(0x1fec)			=		NorderClockCloseMin		;
// *(uint8_t xdata *)(0x1fed)		=			NorderClockOpenHour	;
*(uint8_t xdata *)(0x1fee)	=		function;

		*(uint8_t xdata *)(0x1fe6)= checkNum1;
	  *(uint8_t xdata *)(0x1fe7)= checkNum2;
	*(uint8_t xdata *)(0x1fe8)  =lastCurTemp;
	*(uint8_t xdata *)(0x1fe9)=lastGear;
	iap_off();
}
